<?php
class BrandAction extends BaseAction
{
    public function index()
    {
        $this->seoSet('品牌列表');
        $this->assign('nav', 3);
        //获取所有品牌字母数据
        $initials = D('Brand')->getInitials();
        $this->assign('initials', $initials);
        $this->display();
    }

    /**
     * 根据品牌标示获取品牌信息
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getBrandsByAjax()
    {
        $brands = $this->getBrands();
        if ($brands) {
            $this->assign('brands', $brands);
            $this->ajaxReturn($this->fetch(), 0, 1);
        } else {
            $this->ajaxReturn('', 0, 0);
        }
    }

    /**
     * 根据首字母获取品牌
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getBrands()
    {
        $BrandModel = D('Brand');
        $brands = array();
        $map = array();
        $map['initials'] = strtoupper($this->_get('i'));
        if ($map['initials']) {
            $brands = $BrandModel->getList($map, null);
            //获取品牌图片
            if ($brands) {
                $uid = getLoginUserInfo();
                $BrandAttentionModel = D('BrandAttention');
                foreach ($brands as $key => $brand) {
                    $brands[$key]['image_url'] = $BrandModel->getBrandImage($brand['image']);
                    $brands[$key]['is_att'] = 0;
                }
                if ($uid) {
                    $BrandAttentionModel->checkUserIsAttrBrands($uid, $brands);
                }
            }
        }
        return $brands;
    }
}

?>